//社保基数管理 显示表格及js实体

Ext.define('SocialInsurance', {
    extend: 'Ext.data.Model',
    fields: [
        "Id"
	    , "CompanyId"   //公司Id
		, "CompanyName"   //公司名称
		, "Name"   //社保名称
		, "CompanyBase"   //企业基数
		, "CompanyRatio"   //企业比例
		, "CompanyPlus"   //企业附加金额
		, "PersonalBase"   //个人基数
		, "IsFixed"   //是否固定
		, "PersonalRatio"   //个人比例
		, "PersonalPlus"   //个人附加金额
	],
    idProperty: "Id"
});

Ext.define('SHApp.CompanyManage.SocialInsurance.Grid', {
    extend: 'BLBTSystem.grid',
    alias: 'shapp.companymanage.grid',
    requires: ['SHApp.CompanyManage.SocialInsurance.Form'],
    txtCompanyNameID: 'txtCompanyName',
    txtNameID: 'txtName',
    dataModel: "SocialInsurance",
    dataUrl: "api/socialinsurance?format=json",
    initComponent: function () {
        var me = this;
        Ext.apply(this);
        me.btnAddID += me.id;
        me.btnEditID += me.id;
        me.btnDeleteID += me.id;
        me.txtCompanyNameID += me.id;
        me.txtNameID += me.id;
        this.creatTbar();
        this.creatColumns();
        this.callParent(arguments);
        this.checkBtnPermission(me.pvalue);
    },
    creatColumns: function () {
        var me = this;
        me.columns = [{
            text: "Id",
            flex: 1,
            dataIndex: 'Id',
            sortable: false,
            hidden: true
        }, {
            text: "公司Id",
            width: 100,
            dataIndex: 'CompanyId',
            sortable: true,
            hidden: true
        }, {
            text: "公司名称",
            width: 100,
            dataIndex: 'CompanyName',
            sortable: true
        }, {
            text: "社保名称",
            width: 100,
            dataIndex: 'Name',
            sortable: true
        }, {
            text: "企业基数",
            width: 100,
            dataIndex: 'CompanyBase',
            sortable: true
        }, {
            text: "企业比例",
            width: 100,
            dataIndex: 'CompanyRatio',
            sortable: true
        }, {
            text: "企业附加金额",
            width: 100,
            dataIndex: 'CompanyPlus',
            sortable: true
        }, {
            text: "个人基数",
            width: 100,
            dataIndex: 'PersonalBase',
            sortable: true
        }, {
            text: "是否固定",
            flex: 1,
            dataIndex: 'IsFixed',
            renderer: function (v) {
                if (v) {
                    return "是";
                } else {
                    return "否";
                }
            }
        }, {
            text: "个人比例",
            width: 100,
            dataIndex: 'PersonalRatio',
            sortable: true
        }, {
            text: "个人附加金额",
            width: 100,
            dataIndex: 'PersonalPlus',
            sortable: true
        }
		]
    },
    creatTbar: function () {
        var me = this;
        me.tbar = [
            {
                xtype: "companyComboBox",
                fieldLabel: "公司名称",
                name: "CompanyName",
                labelWidth: 60,
                width: 260,
                id: me.txtCompanyNameID
            }, {
                xtype: 'textfield',
                disabled: false,
                fieldLabel: '社保名称:',
                labelWidth: 60,
                name: 'Name',
                id: me.txtNameID,
                width: 180
            }, {
                xtype: 'button',
                text: '查询',
                iconCls: 'icon-btn-search',
                handler: function () {
                    me.clearFilters();
                    var vCompanyName = me.down("#" + me.txtCompanyNameID).getDisplayValue();
                    if (vCompanyName && vCompanyName.length > 0) {
                        me.addFilter("CompanyName", vCompanyName);
                    }
                    var vName = me.down("#" + me.txtNameID).getValue();
                    if (vName && vName.length > 0) {
                        me.addFilter("Name", vName);
                    }
                    me.loadByFilter();
                }
            }, '->', {
                xtype: 'button',
                text: '添加',
                id: me.btnAddID,
                iconCls: 'icon-btn-add',
                handler: function () {
                    var win = me.getForm('SHApp.CompanyManage.SocialInsurance.Form');
                    win.loadRecord(new SocialInsurance({ Id: null, CompanyBase: 0, CompanyRatio: 0, CompanyPlus: 0, PersonalBase: 0, PersonalRatio: 0, PersonalPlus: 0 }));
                    win.Show("添加");
                }
            }, ' ', {
                xtype: 'button',
                disabled: true,
                id: me.btnEditID,
                text: '修改',
                iconCls: 'icon-btn-edit',
                handler: function () {
                    var rs = me.getSelectionModel().getSelection();
                    if (rs) {
                        if (rs.length > 0) {
                            // rs[0].data.StartDate = formatDate(rs[0].data.StartDate);                           
                            me.EditData(me.getForm('SHApp.CompanyManage.SocialInsurance.Form'));
                        }
                    }
                }
            }, ' ', {
                xtype: 'button',
                disabled: true,
                id: me.btnDeleteID,
                text: '删除',
                iconCls: 'icon-btn-delete',
                handler: function () {
                    me.DeleteData();
                }
            }
        ]
    }
})

